package com.huaxonline.boot.demo;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;

public class DoubleColorBall {

    public static void main(String[] args) {
        generateLotteryNumbers(5); // 生成5注双色球号码
    }

    /**
     * 生成指定数量的双色球号码
     * @param count 要生成的注数
     */
    public static void generateLotteryNumbers(int count) {
        for (int i = 1; i <= count; i++) {
            List<Integer> redBalls = generateRedBalls();
            int blueBall = generateBlueBall();

            System.out.printf("第%02d注: 红球: %s  蓝球: %02d%n",
                    i, formatNumbers(redBalls), blueBall);
        }
    }

    /**
     * 生成红球号码（6个不重复的1-33号码）
     */
    private static List<Integer> generateRedBalls() {
        List<Integer> redBalls = new ArrayList<>();
        for (int i = 1; i <= 33; i++) {
            redBalls.add(i);
        }
        Collections.shuffle(redBalls);
        List<Integer> selected = redBalls.subList(0, 6);
        Collections.sort(selected);
        return selected;
    }

    /**
     * 生成蓝球号码（1个1-16号码）
     */
    private static int generateBlueBall() {
        return new Random().nextInt(16) + 1;
    }

    /**
     * 格式化数字列表为两位字符串格式
     */
    private static String formatNumbers(List<Integer> numbers) {
        StringBuilder sb = new StringBuilder();
        for (int num : numbers) {
            sb.append(String.format("%02d ", num));
        }
        return sb.toString().trim();
    }
}